package com.cade.agriculturemall.view.home.promotion;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cade.agriculturemall.R;
import com.cade.agriculturemall.base.BaseAdapter;
import com.cade.agriculturemall.base.BaseViewHolder;
import com.cade.agriculturemall.model.GoodsDetailEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/4/28 0028.
 */

public class PromotionAdapter extends BaseAdapter<BaseViewHolder> {
    private List<GoodsDetailEntity> mList = new ArrayList<>();
    GoodsDetailEntity entity = new GoodsDetailEntity();
    Context mContext;

    public PromotionAdapter(Context context) {
        mContext = context;
    }

    @Override
    public void onBindViewHolderWrapper(BaseViewHolder holder, int position) {
        ImageView imageView = holder.findViewById(R.id.page_list_fragment_item_imageview);
        TextView tvTitle = holder.findViewById(R.id.page_list_fragment_item_title);
        TextView tvPriceNew = holder.findViewById(R.id.page_list_fragment_item_price_new);
        TextView tvSellOffs = holder.findViewById(R.id.fragment_page_item_sell_offs);

        if (mList != null) {
            GoodsDetailEntity mEntity = mList.get(position);
            if (mEntity.getPicture().size() > 0)
                Glide.with(mContext).load(mEntity.getPicture().get(0))
                        .into(imageView);
            tvTitle.setText(mEntity.getTitle());
            tvTitle.setTextSize(10);
            tvPriceNew.setText("￥ " + mEntity.getPriceNew());
            tvPriceNew.setTextSize(10);
//            tvPriceOld.setText("￥ "+mEntity.getPriceOld());
            tvSellOffs.setText(mEntity.getSellOff() != null ? mEntity.getSellOff() + "人付款" : "0 人付款");

            tvSellOffs.setTextSize(8);
        }
    }

    public List<GoodsDetailEntity> getList() {
        return mList;
    }

    public void setList(List<GoodsDetailEntity> list) {
        this.mList = list;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent, R.layout.page_list_fragment_item);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }
}
